Skip to content

feat(snap-account-service): add migration logic + keyring v2 support#8732

Open
ccharly wants to merge 3 commits into
cc/feat/snap-account-service-account-group-eventsfrom
cc/feat/snap-account-service-keyring-v2-support
Open

feat(snap-account-service): add migration logic + keyring v2 support#8732
ccharly wants to merge 3 commits into
cc/feat/snap-account-service-account-group-eventsfrom
cc/feat/snap-account-service-keyring-v2-support

Conversation

@ccharly
Copy link
Copy Markdown
Contributor

@ccharly ccharly commented May 7, 2026

Explanation

Add migration logic to migrate from the legacy Snap keyring to the new architecture with 1 Snap keyring v2 per Snaps.

Also enhance :ensureReady so consumers can safely call :withKeyringV2 to get the associated Snap keyring v2 instance before using it.

References

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Introduces new keyring migration and automatic v2 keyring creation logic that mutates KeyringController state and removes the legacy Snap keyring, which could impact account availability if migration edge-cases occur.

Overview
Adds a concurrent-safe SnapAccountService.migrate() that migrates accounts out of the legacy global Snap keyring into per-Snap KeyringType.Snap (v2) keyrings, then removes the legacy keyring entry.

Updates ensureReady to always run migration first and to atomically create a v2 keyring for the requested Snap if missing, before waiting on Snap platform readiness. Adds @metamask/keyring-api dependency and expands tests to cover migration concurrency, account grouping-by-snap, and v2 keyring auto-creation behavior.

Reviewed by Cursor Bugbot for commit 8452267. Bugbot is set up for automated code reviews on this repo. Configure here.

Base automatically changed from cc/feat/snap-account-service-track-snaps to main May 7, 2026 15:23
@ccharly ccharly force-pushed the cc/feat/snap-account-service-keyring-v2-support branch from 96269d0 to 43c238b Compare May 12, 2026 10:50
@ccharly ccharly changed the base branch from main to cc/feat/snap-account-service-account-group-events May 12, 2026 10:50
@ccharly ccharly changed the title feat(snap-account-service): add keyring v2 support feat(snap-account-service): add migration logic + keyring v2 support May 12, 2026
@ccharly ccharly marked this pull request as ready for review May 12, 2026 10:57
@ccharly ccharly requested review from a team as code owners May 12, 2026 10:57
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8452267. Configure here.

this.#migratePromise = this.#migrate();
}
return await this.#migratePromise;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed migration permanently cached, blocking all retries

Medium Severity

#migratePromise caches the very first promise returned by #migrate() and never resets it. If migration fails (e.g., addNewKeyring or removeKeyring rejects), the rejected promise is permanently stored. Every subsequent call to migrate() — including from ensureReady() — returns this same rejected promise with no retry path. This effectively disables all snap account functionality until the app is fully restarted.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8452267. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant